package com.swpu.service_sport.service.impl;

import com.swpu.service_sport.entity.Sport;
import com.swpu.service_sport.entity.SportCategory;
import com.swpu.service_sport.entity.vo.SportCategoryVo;
import com.swpu.service_sport.mapper.SportMapper;
import com.swpu.service_sport.service.SportCategoryService;
import com.swpu.service_sport.service.SportService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chaichai
 * @since 2024-02-23
 */
@Service
public class SportServiceImpl extends ServiceImpl<SportMapper, Sport> implements SportService {


    @Autowired
    private SportCategoryService sportCategoryService;
    @Override
    public List<SportCategoryVo> getSportListInfo() {
        List<SportCategory> sportCategories = sportCategoryService.getSportCategories();
        List<Sport> sportList = this.list(null);
        ArrayList<SportCategoryVo> sportCategoryVos = new ArrayList<>();
        for (SportCategory sportCategory : sportCategories) {
            SportCategoryVo sportCategoryVo = new SportCategoryVo();
            sportCategoryVo.setId(sportCategory.getId());
            sportCategoryVo.setCategoryName(sportCategory.getCategoryName());
            ArrayList<Sport> subSportList = new ArrayList<>();
            for (Sport sport : sportList) {
                if (sport.getCategoryId().equals(sportCategory.getId())){
                    subSportList.add(sport);
                }
            }
            sportCategoryVo.setSubSports(subSportList);
            sportCategoryVos.add(sportCategoryVo);
        }
        return sportCategoryVos;
    }
}
